package cliente;

import java.util.HashMap;

public class IU_Ranking extends javax.swing.JFrame {

    // Inicialização de instância única de IU_Ranking
    private static final IU_Ranking theIU_Ranking = new IU_Ranking();

    // Construtor privado
    private IU_Ranking(){
        initComponents();
    }

    // Ponto de acesso à instância única
    public static IU_Ranking getIU_Ranking(){
        return theIU_Ranking;
    }


    public void exibirTela(HashMap<String, Integer> ranking){
        IU_Inicial.getIU_Inicial().desabilitarTela();
        Object[][] matrix = new Object[ranking.entrySet().size()][2];
        
        for(int count=0;count<ranking.entrySet().size();count++){
            matrix[count][0]=ranking.keySet().toArray()[count];
            matrix[count][1]=ranking.values().toArray()[count];
        }
        getIU_Ranking().setVisible(true);
             
        tabelaRanking_Ranking.setModel(new javax.swing.table.DefaultTableModel(
            matrix,
            new String [] {
                "Nome do Jogador", "Vitorias"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            @Override
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaRanking_Ranking = new javax.swing.JTable();
        botaoVoltar_Ranking = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Ranking");
        setName("frame_Ranking"); // NOI18N
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(51, 153, 0));

        tabelaRanking_Ranking.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Joao", new Integer(22)},
                {"Maria", new Integer(21)},
                {"Jose", new Integer(5)},
                {"Jonas", new Integer(2)}
            },
            new String [] {
                "Nome do Jogador", "Vitorias"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tabelaRanking_Ranking);

        botaoVoltar_Ranking.setText("Voltar");
        botaoVoltar_Ranking.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoVoltar_RankingActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addComponent(botaoVoltar_Ranking, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoVoltar_Ranking)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoVoltar_RankingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoVoltar_RankingActionPerformed
        // TODO add your handling code here:
        IU_Jogo.getIU_Jogo().fecharTela();
        IU_Inicial.getIU_Inicial().habilitarTela();
        this.dispose();
    }//GEN-LAST:event_botaoVoltar_RankingActionPerformed

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new IU_Ranking().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoVoltar_Ranking;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabelaRanking_Ranking;
    // End of variables declaration//GEN-END:variables

}
